from django.shortcuts import render
from django.shortcuts import HttpResponse
from django.shortcuts import redirect
# Create your views here.

def login(request):
	error_msg = ''
	if request.method == "POST":
		user = request.POST.get('user')
		pwd = request.POST.get('pwd')

		if user == 'root' and pwd == '123':
			# error_msg = ''
			return redirect("/home")

		else:
			error_msg = "wrong password"
	return render(request, 'login.html', {'error_msg':error_msg})

USER_LIST = [{'username': 'aa', 'email':'bb', 'gender':'cc'}]
USER_SET = set(['aa'])
def home(request):
	if request.method == 'POST':
		u = request.POST.get('username')
		e = request.POST.get('email')
		g = request.POST.get('gender')
		temp = {'username': u, 'email': e, 'gender': g}
		if u not in USER_SET:
			USER_LIST.append(temp)
			USER_SET.add(u)

	return render(request, 'home.html', {'user_list': USER_LIST})